<?php
/**
 * @file
 * Contains theme preprocess functions
 */
 
 /**
  * Override or insert variables into the html template.
  */
function shopa_preprocess_html(&$vars) {
	drupal_add_css(path_to_theme() . '/stylesheet/prettyPhoto.css');
	drupal_add_css(path_to_theme() . '/stylesheet/responsive.css');
  	drupal_add_css(path_to_theme() . '/stylesheet/style.css');
  	drupal_add_css(path_to_theme() . '/stylesheet/styles.css');
  	drupal_add_css(path_to_theme() . '/stylesheet/user.css');
	drupal_add_css(path_to_theme() . '/stylesheet/woocommerce-custom.css');
	
	drupal_add_js(path_to_theme() . '/js/jquery-1.9.1/jquery-ui-1.10.3.custom.min.js');
	drupal_add_js(path_to_theme() . '/js/jquery.prettyPhoto.js');
		
	drupal_add_js(path_to_theme() . '/js/jquery-ext-3.4.1/custom.js');
	drupal_add_js(path_to_theme() . '/js/jquery-ext-3.4.1/jquery.easing.min.js');
	drupal_add_js(path_to_theme() . '/js/jquery-ext-3.4.1/jquery.flexslider-min.js');
	drupal_add_js(path_to_theme() . '/js/jquery-ext-3.4.1/jquery.hoverIntent.minified.js');
	drupal_add_js(path_to_theme() . '/js/jquery-ext-3.4.1/jquery.jcarousel.min.js');
	drupal_add_js(path_to_theme() . '/js/jquery-ext-3.4.1/single-product-1.6.5.1.min.js');
}

/**
 * Format submitted by in articles
 */
function shopa_preprocess_node(&$vars) {
  $node = $vars['node'];
  $vars['date'] = format_date($node->created, 'custom', 'd M Y');

  if (variable_get('node_submitted_' . $node->type, TRUE)) {
    $vars['display_submitted'] = TRUE;
    $vars['submitted'] = t('By @username on !datetime', array('@username' => strip_tags(theme('username', array('account' => $node))), '!datetime' => $vars['date']));
    $vars['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : '';
    
    // Add a footer for post
    $account = user_load($vars['node']->uid);
    $vars['shopa_postfooter'] = '';
    if (!empty($account->signature)) {  
      $postfooter = "<div class='post-footer'>" . $vars['user_picture'] . "<h3>" . check_plain(format_username($account)) . "</h3>";
      $cleansignature = strip_tags($account->signature);
      $postfooter .= "<p>" . check_plain($cleansignature) . "</p>";
      $postfooter .= "</div>";
      $vars['shopa_postfooter'] = $postfooter;
    } 
  }
  else {
    $vars['display_submitted'] = FALSE;
    $vars['submitted'] = '';
    $vars['user_picture'] = '';
  }
  
  // Remove Add new comment from teasers on frontpage
  
  if ($vars['is_front']) {
    unset($vars['content']['links']['comment']['#links']['comment-add']);
    unset($vars['content']['links']['comment']['#links']['comment_forbidden']);
  }
  
}

/**
 * Format submitted by in comments
 */
function shopa_preprocess_comment(&$vars) {
  $comment = $vars['elements']['#comment'];
  $node = $vars['elements']['#node'];
  $vars['created']   = format_date($comment->created, 'custom', 'd M Y');
  $vars['changed']   = format_date($comment->changed, 'custom', 'd M Y');
  $vars['submitted'] = t('By @username on !datetime at about @time.', array('@username' => strip_tags(theme('username', array('account' => $comment))), '!datetime' => $vars['created'], '@time' => format_date($comment->created, 'custom', 'H:i')));
}

/**
 * Change button to Post instead of Save
 */
function shopa_form_comment_form_alter(&$form, &$form_state, &$form_id) {
 $form['actions']['submit']['#value'] = t('Post');
 $form['comment_body']['#after_build'][] = 'configure_comment_form'; 
}

function configure_comment_form(&$form) {
  $form['und'][0]['format']['#access'] = FALSE;
  return $form;
}

function shopa_button($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'submit';
  element_set_attributes($element, array('id', 'name', 'value'));

  $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
  $element['#attributes']['class'][] = 'button alt';
  if (!empty($element['#attributes']['disabled'])) {
    $element['#attributes']['class'][] = 'form-button-disabled';
  }

  return '<button' . drupal_attributes($element['#attributes']) . '><span class="s_text">'.$element['#value'].'</span></button>';
}